<?php
namespace app\admin\controller;

use think\Controller;
use app\admin\model\Bbs;
use app\admin\model\Blog ;
use think\facade\Request;
 

class Index extends Controller
{
   
    public function index() 
    {
            $this->assign('title', '后台首页');

            $bbs  = Bbs::show(8);
            $blog = Blog::show(8);
             
            $this->assign('bbs', $bbs);
            $this->assign('blog', $blog);
            
            // 渲染模板输出
            return $this->fetch('index');

 
    }
    public function bbs() 
    {


 

            $list = Bbs::show();
            // 把分页数据赋值给模板变量list
            $this->assign('list', $list);
            // 渲染模板输出
            return $this->fetch();

 
    }

    public function add(){

      

     if (Request::isPost()) {
 
        $title   = input('title'); 
        $content = input('content'); 

        if ($title=='') {
           
            //错误页面的默认跳转页面是返回前一页，通常不需要设置
            $this->error('标题不能为空');
        }

        $list = Bbs::add($title,$content);


                          
        return     $this->success('留言成功');
     


     }

     // 渲染模板输出
    return $this->fetch();

    }

    public function hello($name = 'ThinkPHP5')
    {
        return 'hello,' . $name;
    }
    public function ok()
    {
        return 'hello,';
    }
    public function tom(){
 
    }
    public function view(){


        $id = input('id'); 
        $view = Bbs::view($id);
        $this->assign('view', $view);
        return $this->fetch();
    }
}
